package com.xdq.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author: 徐东强
 * @date: 2018/10/14 下午11:43
 * @description:
 **/
@RestController
@RequestMapping("/producer")
public class ProducerController {

    private final KafkaTemplate kafkaTemplate;

    @Autowired
    public ProducerController(KafkaTemplate kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    @GetMapping("/productAll")
    public void productAll() throws InterruptedException {
        for (int i = 0; i< 1000;i++){
//            Thread.sleep(3000);
            if (i==5||i==15||i==25||i==35){
                this.kafkaTemplate.send("event_topic", null);
            } else {
                this.kafkaTemplate.send("event_topic", "message"+i);
            }
        }
    }
    @GetMapping("/product")
    public void product() throws InterruptedException {
        while (true){
            Thread.sleep(2000);
            this.kafkaTemplate.send("event_topic", "{\"distinct_id\":\"16667a0ed8b38b-053c3219786036-c467463-373248-16667a0ed8c326\",\"lib\":{\"$lib\":\"js\",\"$lib_method\":\"code\",\"$lib_version\":\"1.10.1\"},\"properties\":{\"$screen_height\":864,\"$screen_width\":432,\"$lib\":\"js\",\"$lib_version\":\"1.10.1\",\"$latest_traffic_source_type\":\"直接流量\",\"$latest_referrer\":\"\",\"$latest_referrer_host\":\"\",\"$latest_search_keyword\":\"未取到值_直接打开\",\"$referrer\":\"\",\"$referrer_host\":\"\",\"$url\":\"https://odpwx.cjddealer.com.cn/comments/page-dealer/33159/o0fh2jqKuiqNbGapNk611VVK7W8U\",\"$url_path\":\"/comments/page-dealer/33159/o0fh2jqKuiqNbGapNk611VVK7W8U\",\"$title\":\"经销商详情\",\"$is_first_day\":true,\"$is_first_time\":true,\"$ip\":\"113.108.186.130\",\"$os\":\"Android\",\"$os_version\":\"7.1.1\",\"$browser\":\"Chrome Mobile\",\"$browser_version\":\"62.0.3202.84\",\"$is_login_id\":false,\"$city\":\"广州\",\"$province\":\"广东\",\"$country\":\"中国\"},\"type\":\"track\",\"event\":\"$pageview\",\"time\":1539336893102,\"map_id\":\"16667a0ed8b38b-053c3219786036-c467463-373248-16667a0ed8c326\",\"user_id\":2154522180714903719,\"recv_time\":1539336893102,\"extractor\":{\"f\":\"(dev=fd11,ino=13107747)\",\"o\":2159857,\"n\":\"access_log.2018101217\",\"s\":117086156,\"c\":117086156,\"e\":\"data01.boldseas.sa\"},\"project_id\":3,\"project\":\"production\"}");
        }
    }

}
